﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;

namespace Frogger
{
    class RollingBackground
    {
        private Vector2 _speed = new Vector2(0,0);
        private Texture2D _textureImage;
        private int _yPos = 0;
        private Vector2 _frameSize;

        public RollingBackground(Texture2D texture, Vector2 frameSize)
        {
            _textureImage = texture;
            _frameSize = frame;
        }

        public void Update(GameTime gameTime, Rectangle clientBounds, Frog myFrog) 
        {
            if (myFrog.GetPosition().Y < clientBounds.Height / 3 * 2)
            {        
                _yPos += myFrog.GetSpeed().Y;
                if (_yPos >= clientBounds.Height)
                    _yPos = 0;
            }
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
           /* spriteBatch.Draw(textureImage,
                new Rectangle(0, 0, (int)frameSize.X, (int)frameSize.Y - yPos), 
                new Rectangle(0, yPos, (int)frameSize.X, (int)frameSize.Y - yPos), 
                Color.White, 0, Vector2.Zero, SpriteEffects.None, 0);
            spriteBatch.Draw(textureImage,
               new Rectangle(0,(int)frameSize.Y-yPos,(int)frameSize.X,yPos), 
               new Rectangle(0,0,(int)frameSize.X,yPos),
               Color.White, 0, Vector2.Zero, SpriteEffects.None, 0);*/

            spriteBatch.Draw(_textureImage,
                new Rectangle(0, 0, (int)_frameSize.X, _yPos),
                new Rectangle(0, (int)_frameSize.Y-_yPos, (int)_frameSize.X, _yPos),
                Color.White, 0, Vector2.Zero, SpriteEffects.None, 0);
            spriteBatch.Draw(_textureImage,
               new Rectangle(0, _yPos, (int)_frameSize.X, (int)_frameSize.Y-_yPos),
               new Rectangle(0, 0, (int)_frameSize.X, (int)_frameSize.Y-_yPos),
               Color.White, 0, Vector2.Zero, SpriteEffects.None, 0);

        }

        public void SetSpeed(Vector2 speed)
        {
            _speed = speed;
        }
        public Vector2 getSpeed()
        {
            return _speed;
        }
    }
}
